package com.huika.dealontop.control.shops.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.BaseFra;
import com.huika.dealontop.support.domain.ProductDetailsBean;
import com.huika.dealontop.utils.DateTimeTool;
import com.huika.dealontop.utils.UIUtils;
import com.huika.huikalib.utils.StringUtils;

/**
 * Author: Victor Wu <br/>
 * Email: victor-wu*foxmail.com <br/>
 * Time: 2015/11/23 13:23 <br/>
 * Description: 须知
 */
public class ProductNoticeFragment extends BaseFra {
    private ProductDetailsBean.ProductBean productDetailsBean;
    private View view;

    private View ll_productRuleName;
    private View ll_productOther;

    private ScrollView mSvContent;
    public ScrollView getScrollView() {
        return mSvContent;
    }

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        mSvContent = (ScrollView) View.inflate(UIUtils.getContext(), R.layout.fragment_notice_list, null);
        view = View.inflate(UIUtils.getContext(), R.layout.fragment_product_notice, null);
        ll_productRuleName = view.findViewById(R.id.ll_productRuleName);
        ll_productOther = view.findViewById(R.id.ll_productOther);

        if(productDetailsBean != null){
            refreshUI();
        }
        mSvContent.addView(view);
        return mSvContent;
    }

    private void refreshUI() {
        //有效期
        ((TextView)view.findViewById(R.id.tv_product_detail_validity)).setText(
                UIUtils.getFormatString(R.string.product_validity_show,
                        DateTimeTool.dmyDate(productDetailsBean.getStartDate()),
                        DateTimeTool.dmyDate(productDetailsBean.getEndDate()))
        );
        //使用时间
        ((TextView) view.findViewById(R.id.tv_product_detail_useTime)).setText(productDetailsBean.getUsePeriod());
        //预约提醒
        ((TextView) view.findViewById(R.id.tv_product_detail_reservation)).setText(productDetailsBean.getBespeakRemind());
        //使用规则
        ((TextView) view.findViewById(R.id.tv_product_detail_productRuleName)).setText(productDetailsBean.getUseLimit());
        ll_productRuleName.setVisibility(StringUtils.isEmpty(productDetailsBean.getUseLimit()) ? View.GONE : View.VISIBLE );
        //补充说明
        ((TextView) view.findViewById(R.id.tv_product_detail_other_help)).setText(productDetailsBean.getOther());
        ll_productOther.setVisibility(StringUtils.isEmpty(productDetailsBean.getOther()) ? View.GONE : View.VISIBLE );

    }

    public void setProductDetails(ProductDetailsBean.ProductBean productDetails){
        this.productDetailsBean = productDetails;
    }

}
